package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.po.Member;
import com.project.entity.qo.MemberQo;
import com.project.result.ResponseResult;
import com.project.service.MemberService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName:
 * @Package:
 * @ClassName:
 * @Author: ZhaoLongShi
 * @CreateDate:
 */
@SuppressWarnings("all")
@RestController
@RequiresRoles("admin")
@RequestMapping("/member")
public class MemberController {
    @Resource
    private MemberService memberService;

    /**
     * 查询所有会员（分页）
     *
     * @return
     */
    @GetMapping("/select/all/member")
    public ResponseResult selectAllMember(int current) {
        ResponseResult<Page<Member>> result = memberService.selectAllMember(current);
        return result;
    }

    @GetMapping("/select/member")
    public ResponseResult selectMemberByType(int cardType){
        ResponseResult<List<Member>> result = memberService.selectByType(cardType);
        return result;
    }

    /**
     * 根据会员ID更新会员信息
     *
     * @param memberQo
     * @return
     */
    @PostMapping("/update/member")
    public ResponseResult updateMemberById(@RequestBody MemberQo memberQo) {
        ResponseResult result = memberService.updateMemberById(memberQo);
        return result;
    }

    /**
     * 根据会员ID删除会员（可批量）
     *
     * @param idList
     * @return
     */
    @PostMapping("/delete/member")
    public ResponseResult deleteMemberByIds(@RequestBody List<Long> idList) {
        ResponseResult result = memberService.deleteMemberByIds(idList);
        return result;
    }

    /**
     * 添加会员
     *
     * @param memberQo
     * @return
     */
    @PutMapping("/add/member")
    public ResponseResult addMember(@RequestBody MemberQo memberQo) {
        ResponseResult result = memberService.addMember(memberQo);
        return result;
    }

}
